﻿function New-TSMAdministrator {
    <#
        .SYNOPSIS
            Define new TSM administrator
                    
        .DESCRIPTION
            The New-TSMAdministrator registers a new TSM administrator
        
        .EXAMPLE
            New-TSMAdministrator "username" "password

        .NOTES
            Contributors:  David Seibel
            Last Revision Date: 06/04/2015
    #>
    [CmdletBinding()]
    Param(
        [Parameter(Position = 0, Mandatory = $true)]
        $Name,
        
        [Parameter(Position = 1)]
        $Password,

        [ValidateRange(0,9999)]
        [Int32]$PasswordExpirationDays,

        $Contact,
        
        [ValidateSet("Yes","No")]
        $ForcePasswordReset = "No",

        $EmailAddress,
        
        [ValidateSet("Local","LDAP")]
        $Authentication = "Local",

        [ValidateSet("Yes","No","Default")]
        $SSLRequired = "Default",
        
        [ValidateSet("Yes","No")]
        $Alert = "No"
    )

    if ($Authentication -eq "Local" -and (($Password -eq $null) -or ($Password -eq ""))) {
        throw "Password is required when using local authentication!"
    }
    $command = "Register Admin $Name $Password PassExp=$PasswordExpirationDays EmailAddress='$EmailAddress' Authentication=$Authentication SSLRequired=$SSLRequired Alert=$Alert"

    $output = Invoke-TSMCommand -Command $command

    return $output
}